package cn.ht.volatiledemo;

import java.util.concurrent.TimeUnit;

/**
 * @author ht
 * @Description: 传统单例模式
 * @date 2020-5-20
 */
public class SingletonDemo {

    public static  SingletonDemo instance = null;

    private SingletonDemo(){
        System.out.println(Thread.currentThread().getName()+"\t 启动了构造方法SingletonDemo()！");
    }

    public static SingletonDemo getIntance(){
        if(instance == null){
            instance = new SingletonDemo();
        }
        return instance;
    }

    public static void main(String[] args) {
        for (int i = 1; i <= 10 ; i++) {
            new Thread(()->{
                SingletonDemo.getIntance();
            },String.valueOf(i)).start();
        }
    }

}
